package com.emm.yixun.mobile.ui.from;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.adapter.AnnexAdapter;
import com.emm.yixun.mobile.adapter.NewFromAdapter;
import com.emm.yixun.mobile.adapter.PhoneSelectAdapter;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.model.AddPayDeposit;
import com.emm.yixun.mobile.model.AddpirModel;
import com.emm.yixun.mobile.model.GetConsultantList;
import com.emm.yixun.mobile.model.GetCustomerDetail;
import com.emm.yixun.mobile.model.GetDictionaryList.RqBusNumList;
import com.emm.yixun.mobile.model.GetPayDepositDetail;
import com.emm.yixun.mobile.model.NewClassKehuModel;
import com.emm.yixun.mobile.model.NewGetDictionaryList;
import com.emm.yixun.mobile.ui.housing.HousingresourcesActivity;
import com.emm.yixun.mobile.ui.signed.NewSignedActivity.ImageListInfo;
import com.eroad.product.tools.MyGridView;
import com.eroad.product.tools.MyListView;
import com.eroad.product.tools.PickerView;
import com.eroad.product.tools.PickerView.onSelectListener;
import com.eroad.product.tools.PopuContent;
import com.eroad.product.tools.Time_SelectPicPopupWindow;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nui.multiphotopicker.model.ImageItem;
import com.nui.multiphotopicker.view.ImageBucketChooseActivity;
import com.yanzhenjie.album.Album;
import com.yixun.app.viewpagerandimag.sample.ViewPagerActivity;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import xf.tools.Loading;
import xf.tools.popu.SelectPicPopupWindow_Test;

/**
 * <p>
 * <b>Title：</b> 新增认筹
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 *
 * @author tangxin
 * @date 2016年12月6日 下午4:09:24
 */
public class NewFromActivity extends BaseActivity {

    private static final String TAG = "NewFromActivity";

    /**
     * 0为新增 非0为修改
     */
    private int OpenType = 0;

    /**
     * 认筹ID
     */
    private String payDepositId;

    /**
     * 客户ID
     */
    private String customerId;

    /**
     * 房源信息
     */
    private boolean IsFangyuan = true;

    /**
     * 客户信息
     */
    private boolean IsKehu = true;

    /**
     * 房源信息
     */
    LinearLayout fangyuan, fangyuan_layout;

    /**
     * 客户信息
     */
    LinearLayout kehu, kehu_layout;

    ImageView rt1, rt2;

    /**
     * 添加客户信息
     */
    ImageView add;

    /* ---公用选择框--- */
    View view;
    PopupWindow popu;
    /**
     * 选中内容
     */
    String selectName;
    /**
     * 选中下标
     */
    int SelectID;
    ArrayList<String> listname;
    /* ---公用选择框--- */

    ArrayList<NewClassKehuModel> list = new ArrayList<NewClassKehuModel>();
    NewFromAdapter adapter;

    MyListView kehuxinxi;

    /**
     * 保存按钮
     */
    TextView is_sure;

    /**
     * 无房认筹
     */
    EditText wufangrc;

    /**
     * 房源是是否为必填 false不是必填 true 必填
     */
    private boolean Isfy = true;

    /**
     * 是否无房认筹
     */
    LinearLayout is_wufangrc;

    /**
     * 同意向房源
     */
    EditText housing_btn;

    /**
     * 房源ID
     */
    private String FrdID = "";

    /**
     * 证件类型
     */
    EditText zj_type;

    /**
     * 选择地址显示view
     */
    EditText addr_ed;

    /**
     * 自定义地址选择器
     */
    private SelectPicPopupWindow_Test popupWindow_Test;

    /**
     * 自定义时间控件
     */
    private Time_SelectPicPopupWindow time_SelectPicPopupWindow;

    /**
     * 选择时间显示view
     */
    EditText time_ed;

    /**
     * 选择地址
     */
    EditText select_address;

    TextView title_main;

    ImageView back_btn;

    /**
     * 认筹日期选择
     */
    EditText from_time;

    /**
     * 经纪人
     */
    EditText p_jjr;

    /**
     * 提交审核
     */
    TextView reject_btn;

    /**
     * 计价面积
     */
    EditText calculateArea_view;

    /**
     * 折前单价
     */
    EditText discountPrice_view;

    /**
     * 折前总价
     */
    EditText discountTotalPrice_view;

    /**
     * 认筹编号
     */
    EditText payDepositCode_view;

    /**
     * 认筹金
     */
    EditText payDepositMoney_view;

    /**
     * 备注
     */
    EditText remark_view;

    /**
     * 姓名
     */
    EditText memberName_view;

    /**
     * 证件号
     */
    EditText documentNumber_vew;

    /**
     * 手机号
     */
    EditText peMobile_view;

    /**
     * 邮编
     */
    EditText pePostcode_view;

    /**
     * 房源标识
     */
    LinearLayout found_1;

    /**
     * 图片附件
     */
    TextView from_htsm_view;

    /**
     * 图片附件grid
     */
    MyGridView grid_phone;

    ArrayList<AddpirModel> ap;

    ArrayList<AddpirModel> ap2 = new ArrayList<AddpirModel>();

    /**
     * 合同扫描适配器
     */
    PhoneSelectAdapter padapter;

    /**
     * 附件布局
     */
    LinearLayout annex_layout;

    /**
     * 附件列表
     */
    MyListView annexList_list;

    /**
     * 附件数量
     */
    TextView annexNum_view;

    /**
     * 用于监听最外层布局高度，判断键盘弹出不展示保存和提交审核的底部菜单
     */
    RelativeLayout background_key;

    /**
     * 底部菜单布局
     */
    LinearLayout buttom_select;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        IsVisibleStatusBar = false;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_from_activity);
        BaseActivity.activity = this;

        customerId = getIntent().getStringExtra("customerId");
        OpenType = getIntent().getIntExtra("OpenType", 0);
        payDepositId = getIntent().getStringExtra("payDepositId");

        initView();

        findViewById(R.id.statusbar_bg).setVisibility(View.GONE);
//		SetRelativiLayoutPadding(R.id.main_head_top_rela);

        initBtn();

        from_time.setText(EmmApplication.dataTime(EmmApplication.geTime(), "yyyy年MM月dd日"));

        if (OpenType == 0)
            getCustomerDetail(customerId);
        else
            SetDetaView();

        getDictionaryList();
    }

    /**
     * <p>
     * <b>Title：</b> 初始化view
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:37:50
     */
    private void initView() {
        fangyuan = (LinearLayout) findViewById(R.id.fangyuan);
        fangyuan_layout = (LinearLayout) findViewById(R.id.fangyuan_layout);
        rt1 = (ImageView) findViewById(R.id.rt1);
        kehu = (LinearLayout) findViewById(R.id.kehu);
        kehu_layout = (LinearLayout) findViewById(R.id.kehu_layout);
        rt2 = (ImageView) findViewById(R.id.rt2);
        add = (ImageView) findViewById(R.id.add);
        kehuxinxi = (MyListView) findViewById(R.id.kehuxinxi);
        is_sure = (TextView) findViewById(R.id.is_sure);
        wufangrc = (EditText) findViewById(R.id.wufangrc);
        is_wufangrc = (LinearLayout) findViewById(R.id.is_wufangrc);
        housing_btn = (EditText) findViewById(R.id.housing_btn);
        zj_type = (EditText) findViewById(R.id.zj_type);
        select_address = (EditText) findViewById(R.id.select_address);
        title_main = (TextView) findViewById(R.id.title_main);
        title_main.setText(getString(R.string.from_activity));
        from_time = (EditText) findViewById(R.id.from_time);
        p_jjr = (EditText) findViewById(R.id.p_jjr);
        reject_btn = (TextView) findViewById(R.id.reject_btn);
        back_btn = (ImageView) findViewById(R.id.back_btn);
        calculateArea_view = (EditText) findViewById(R.id.calculateArea_view);
        discountPrice_view = (EditText) findViewById(R.id.discountPrice_view);
        discountTotalPrice_view = (EditText) findViewById(R.id.discountTotalPrice_view);
        payDepositCode_view = (EditText) findViewById(R.id.payDepositCode_view);
        payDepositMoney_view = (EditText) findViewById(R.id.payDepositMoney_view);
        remark_view = (EditText) findViewById(R.id.remark_view);
        memberName_view = (EditText) findViewById(R.id.memberName_view);
        documentNumber_vew = (EditText) findViewById(R.id.documentNumber_vew);
        peMobile_view = (EditText) findViewById(R.id.peMobile_view);
        pePostcode_view = (EditText) findViewById(R.id.pePostcode_view);
        found_1 = (LinearLayout) findViewById(R.id.found_1);

        from_htsm_view = (TextView) findViewById(R.id.from_htsm_view);
        from_htsm_view.setText("图片附件");
        grid_phone = (MyGridView) findViewById(R.id.grid_phone);
        annex_layout = (LinearLayout) findViewById(R.id.annex_layout);
        annexList_list = (MyListView) findViewById(R.id.annexList_list);
        annexNum_view = (TextView) findViewById(R.id.annexNum_view);
        background_key = (RelativeLayout) findViewById(R.id.background_key);
        buttom_select = (LinearLayout) findViewById(R.id.buttom_select);
    }

    /**
     * <p>
     * <b>Title：</b> 初始化监听事件
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:38:50
     */
    private void initBtn() {
        background_key.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // 比较Activity根布局与当前布局的大小
                int heightDiff = background_key.getRootView().getHeight() - background_key.getHeight();
                if (heightDiff > 100) {
                    // 大小超过100时，一般为显示虚拟键盘事件
                    Log.v(TAG, "---------大于一百--键盘打开");
                    buttom_select.setVisibility(View.GONE);
                } else {
                    // 大小小于100时，为不显示虚拟键盘或虚拟键盘隐藏
                    Log.v(TAG, "---------小于一百--键盘关闭");
                    buttom_select.setVisibility(View.VISIBLE);
                }
            }
        });

        IsOpenOrClose(fangyuan_layout, IsFangyuan, rt1);
        IsOpenOrClose(kehu_layout, IsKehu, rt2);
        back_btn.setVisibility(View.VISIBLE);
        back_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        fangyuan.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DoOpenOrClose(IsFangyuan);
            }
        });
        kehu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DoKehuOpenOrClose(IsKehu);
            }
        });
        add.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                NewClassKehuModel n = new NewClassKehuModel();
                n.setNumber("" + (list.size() + 2));
                list.add(n);
                adapter.SetDate(list);
            }
        });
        adapter = new NewFromAdapter(NewFromActivity.this, list);
        kehuxinxi.setAdapter(adapter);
        is_sure.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EmmApplication.disKey(NewFromActivity.this);
                Loading.hideDialogForLoading();
                Loading.showDialogForLoading(NewFromActivity.this, "正在保存...", false, true, 100000);
                RecordTaskUpdate record = new RecordTaskUpdate("0", OpenType);
                record.execute();
            }
        });
        wufangrc.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listname = new ArrayList<String>();
                listname.add("是");
                listname.add("否");
                SetzpPopu(listname, "无房认筹", wufangrc, 0);
            }
        });
        wufangrc.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                Log.w(TAG, "String===>" + s.toString().trim());
                if ("否".equals(s.toString().trim())) {
                    Isfy = true;
                    is_wufangrc.setVisibility(View.VISIBLE);
                    found_1.setVisibility(View.VISIBLE);
                } else {
                    Isfy = false;
                    is_wufangrc.setVisibility(View.GONE);
                    found_1.setVisibility(View.GONE);
                }
            }
        });
        housing_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EmmApplication.housinglist.clear();
                EmmApplication.IsGet = true;
                Intent intent = new Intent(NewFromActivity.this, HousingresourcesActivity.class);
                intent.putExtra("isNewFrom", true);
                startActivity(intent);
            }
        });
        zj_type.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listname = new ArrayList<String>();
                if (DocumentType != null) {
                    for (int i = 0; i < DocumentType.size(); i++) {
                        listname.add(DocumentType.get(i).getDictionaryName());
                    }
                } else {
                    PopuContent.poPu(NewFromActivity.this, "证件类型获取失败", false, 1);
                }
                SetzpPopu(listname, "证件类型", zj_type, 0);
            }
        });
        documentNumber_vew.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (null != s.toString()) {
                    if ("身份证".equals(zj_type.getText().toString().trim())) {
                        if (s.toString().length() > 18) {
                            documentNumber_vew.setText(s.toString().trim()
                                    .substring(0, s.toString().trim().length() - 1));
                            documentNumber_vew.setSelection(documentNumber_vew.getText().toString().trim().length());
                        }
                    }
                }

            }
        });
        from_time.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                time_ed = from_time;
                // 调用时间选择器
                time_SelectPicPopupWindow = new Time_SelectPicPopupWindow(NewFromActivity.this, keyListener, 0,
                        GetDate(from_time));
                time_SelectPicPopupWindow.showAtLocation(title_main, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
            }
        });
        p_jjr.setText(EmmApplication.getUserName());
        p_jjr.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                getConsultantList();
            }
        });
        reject_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EmmApplication.disKey(NewFromActivity.this);
                Loading.hideDialogForLoading();
                Loading.showDialogForLoading(NewFromActivity.this, "正在提交...", false, true, 100000);
                RecordTaskUpdate record = new RecordTaskUpdate("1", OpenType);
                record.execute();
            }
        });

        SetDate();
        padapter = new PhoneSelectAdapter(NewFromActivity.this, ap, 1);
        grid_phone.setAdapter(padapter);
        grid_phone.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if ("1".equals(ap.get(position).getType())) {
                    ViewPagerActivity.postion = position;
                    ViewPagerActivity.sDrawables.clear();
                    for (int u = 0; u < ap.size(); u++) {
                        if ("1".equals(ap.get(u).getType())) {
                            if ("1".equals(ap.get(u).getIsnet())) {
                                ViewPagerActivity.sDrawables.add("file://" + ap.get(u).getPath());
                            } else {
                                ViewPagerActivity.sDrawables.add(ap.get(u).getPath());
                            }
                        }
                    }
                    Intent intent = new Intent(NewFromActivity.this, ViewPagerActivity.class);
                    intent.putExtra("IsOpenDelete", 0);
                    startActivity(intent);
                }
            }
        });

    }

    Handler h = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 1) {
                EmmApplication.Ts("请选择证件类型");
                documentNumber_vew.setText("");
            }
        }

        ;
    };

    /**
     * <p>
     * <b>Title：</b> 添加默认数据
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:52:00
     */
    private void SetDate() {
        ap = new ArrayList<AddpirModel>();
        AddpirModel a = new AddpirModel();
        a.setIsnet("1");
        a.setType("2");
        a.setPath("");
        ap.add(a);
    }

    /**
     * <p>
     * <b>Title：</b> 获取输入框的时间，转成date返回
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param view
     * @return
     * @author tangxin
     * @date 2016年12月7日 下午3:39:34
     */
    private Date GetDate(EditText view) {
        if (null != view.getText().toString().trim() && !"".equals(view.getText().toString().trim())
                && !"null".equals(view.getText().toString().trim())) {
            DateFormat fmt = new SimpleDateFormat("yyyy年MM月dd日");
            Date date = null;
            try {
                date = fmt.parse(view.getText().toString().trim());
            } catch (ParseException e) {
                date = new Date(System.currentTimeMillis());
                e.printStackTrace();
            }
            return date;
        } else {
            return new Date(System.currentTimeMillis());
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        BaseActivity.activity = this;
        if (EmmApplication.IsGet) {
            EmmApplication.IsGet = false;
            if (EmmApplication.housinglist != null && EmmApplication.housinglist.size() > 0) {
                housing_btn.setText(EmmApplication.housinglist.get(0).getRoomName());
                FrdID = EmmApplication.housinglist.get(0).getRoomId();
                calculateArea_view.setText(EmmApplication.room.getCalculateArea());
                discountPrice_view.setText(EmmApplication.room.getDiscountPrice());
                discountTotalPrice_view.setText(EmmApplication.room.getDiscountTotalPrice());
            }
        }

        SetImage();

        IntentFilter filterr = new IntentFilter();
        filterr.addAction("open_Image_popu");
        registerReceiver(mBroadcastReceiver, filterr);
    }

    private void SetImage() {
        // 0不变 1删除
        if (null != EmmApplication.pir || EmmApplication.pir.size() > 0) {
            if (null != ap) {
                // ap.clear();
            } else {
                ap = new ArrayList<AddpirModel>();
            }
            if (EmmApplication.IsCreate) {// 是否新建，需要创建一个按钮
                EmmApplication.IsCreate = false;
                ap.clear();
                AddpirModel a = new AddpirModel();
                a.setIsnet("1");
                a.setType("2");
                a.setPath("");
                ap.add(a);
            }
            for (int i = 0; i < EmmApplication.pir.size(); i++) {
                int y = 0;
                for (int n = 0; n < ap.size(); n++) {
                    if (EmmApplication.pir.get(i).sourcePath.equals(ap.get(n).getPath())) {
                        y++;
                    }
                }
                if (y > 0) {
                    Log.v(TAG, "已存在，不添加");
                } else {
                    AddpirModel a = new AddpirModel();
                    a.setIsnet(EmmApplication.pir.get(i).type);
                    a.setType("1");
                    a.setPath(EmmApplication.pir.get(i).sourcePath);
                    ap.add(0, a);
                }
            }
            padapter.SetDate(ap);
        }
    }

    /**
     * 广播监听方法 当点击添加图片按钮时，接收到广播，弹出popupwindow
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("open_Image_popu")) {
                popu();
            }
        }
    };

    /**
     * <p>
     * <b>Title：</b>判断各展开状况
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param view
     * @param bl
     * @param view2
     * @author tangxin
     * @date 2016年12月7日 下午3:41:54
     */
    private void IsOpenOrClose(View view, boolean bl, ImageView view2) {
        if (bl) {
            view.setVisibility(View.VISIBLE);
            view2.setImageResource(R.drawable.j_bottom);
        } else {
            view.setVisibility(View.GONE);
            view2.setImageResource(R.drawable.j_top);
        }
    }

    /**
     * <p>
     * <b>Title：</b> 判断操作中的房源模块的展开状况
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param bl
     * @author tangxin
     * @date 2016年12月7日 下午3:42:00
     */
    private void DoOpenOrClose(boolean bl) {
        if (!bl) {
            IsFangyuan = true;
            fangyuan_layout.setVisibility(View.VISIBLE);
            rt1.setImageResource(R.drawable.j_bottom);
        } else {
            IsFangyuan = false;
            fangyuan_layout.setVisibility(View.GONE);
            rt1.setImageResource(R.drawable.j_top);
        }
    }

    /**
     * <p>
     * <b>Title：</b> 判断操作中的客户信息模块的展开状况
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param bl
     * @author tangxin
     * @date 2016年12月7日 下午3:42:09
     */
    private void DoKehuOpenOrClose(boolean bl) {
        if (!bl) {
            IsKehu = true;
            kehu_layout.setVisibility(View.VISIBLE);
            rt2.setImageResource(R.drawable.j_bottom);
        } else {
            IsKehu = false;
            kehu_layout.setVisibility(View.GONE);
            rt2.setImageResource(R.drawable.j_top);
        }
    }

    /**
     * <p>
     * <b>Title：</b> 选项框 type=0.普通，type=1选择经纪人
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param listname
     * @param title
     * @param ed
     * @param type
     * @author tangxin
     * @date 2016年12月7日 下午3:42:22
     */
    @SuppressLint("WrongConstant")
    public void SetzpPopu(final List<String> listname, String title, final EditText ed, final int type) {
        view = LayoutInflater.from(NewFromActivity.this).inflate(R.layout.popu_zp, null);
        popu = new PopupWindow(view, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
        popu.setFocusable(true);
        // EmmApplication.setNumberLog(NewFromActivity.this, 0.5f);//
        // 改变popupwindow范围外的屏幕亮度
        popu.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popu.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popu.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        popu.showAsDropDown(view, 0, 0);
        popu.setFocusable(true);
        popu.setOutsideTouchable(true);
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    popu.dismiss();
                    EmmApplication.setLog(NewFromActivity.this);
                }
                return false;
            }
        });
        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                popu.dismiss();
                EmmApplication.setLog(NewFromActivity.this);
            }
        });

        PickerView select_pick = (PickerView) view.findViewById(R.id.select_pick);

        selectName = listname.get(0);

        TextView shuerbtn = (TextView) view.findViewById(R.id.shuerbtn);
        RelativeLayout relative_all = (RelativeLayout) view.findViewById(R.id.relative_all);

        ImageView dis_btn = (ImageView) view.findViewById(R.id.dis_btn);
        dis_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu.dismiss();
                EmmApplication.setLog(NewFromActivity.this);
            }
        });
        TextView title_select = (TextView) view.findViewById(R.id.title_select);

        title_select.setText(title);

        select_pick.setData(listname);
        select_pick.setOnSelectListener(new onSelectListener() {
            @Override
            public void onSelect(String text, int id) {
                selectName = text;
                SelectID = id;
                if (type == 1) {
                    agentId = id;
                }
            }
        });
        select_pick.setSelected(0);
        shuerbtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 确定
                popu.dismiss();
                EmmApplication.setLog(NewFromActivity.this);
                // EmmApplication.T("选择:" + selectName + "==>ID:" + SelectID);
                ed.setText(selectName);
            }
        });
        relative_all.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }

    OnClickListener keyListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.imageView1:
                    time_SelectPicPopupWindow.dismiss();
                    time_SelectPicPopupWindow.Aprils.clear();
                    time_SelectPicPopupWindow.Years.clear();
                    time_SelectPicPopupWindow.Days.clear();

                    SimpleDateFormat formats = new SimpleDateFormat("yyyy年MM月dd日");
                    Calendar c = Calendar.getInstance();
                    try {
                        c.setTime(formats.parse(time_SelectPicPopupWindow.getLanguage()
                                + time_SelectPicPopupWindow.getType_One() + time_SelectPicPopupWindow.getType()));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                    Date endDate = c.getTime();
                    String str = formats.format(endDate);
                    Log.w(TAG, "str:" + str);
                    time_ed.setText(str);
                    break;
                default:
                    break;
            }
        }
    };
    OnClickListener keyListener2 = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.imageView1:
                    if (TextUtils.isEmpty(popupWindow_Test.getType()) || TextUtils.isEmpty(popupWindow_Test.getType_One())) {
                        EmmApplication.T("亲，您选择的地址有误，请重新选择");
                    } else {
                        addr_ed.setText(popupWindow_Test.getLanguage() + popupWindow_Test.getType()
                                + popupWindow_Test.getType_One());
                        EmmApplication.areaIds = popupWindow_Test.getareaId_one() + "|" + popupWindow_Test.getareaId_two()
                                + "|" + popupWindow_Test.getareaId_three();
                    }
                    Log.w("areaIds:", EmmApplication.areaIds);
                    popupWindow_Test.dismiss();
                    break;
                default:
                    break;
            }
        }

        ;
    };

    /**
     * <p>
     * <b>Title：</b> 编辑修改填充数据
     * </p>
     * <p>
     * <b>Description：</b> 由详情带入数据
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:44:20
     */
    private void SetDetaView() {
        GetPayDepositDetail getpaydepositdetail = EmmApplication.getpaydepositdetail;
        if (null == getpaydepositdetail) {
            return;
        }
        if ("1".equals(getpaydepositdetail.getIsPayDeposit())) {
            wufangrc.setText("是");
            found_1.setVisibility(View.GONE);
        } else {
            wufangrc.setText("否");
            found_1.setVisibility(View.VISIBLE);
            housing_btn.setText(getpaydepositdetail.getPayDepositHouses());

            calculateArea_view.setText(getpaydepositdetail.getCalculateArea());

            discountPrice_view.setText(getpaydepositdetail.getDiscountPrice());

            discountTotalPrice_view.setText(getpaydepositdetail.getDiscountTotalPrice());
        }

        FrdID = getpaydepositdetail.getRoomId();// 填充房源ID

        memberName_view.setText(getpaydepositdetail.getCustomerName());
        zj_type.setText(getpaydepositdetail.getDocumentType());
        documentNumber_vew.setText(getpaydepositdetail.getDocumentNumber());
        peMobile_view.setText(getpaydepositdetail.getCustomerPhone());
        select_address.setText(getpaydepositdetail.getMailPost());
        pePostcode_view.setText(getpaydepositdetail.getPostcode());

        if (null != getpaydepositdetail.getCustomerFamilyList()
                && getpaydepositdetail.getCustomerFamilyList().size() > 0) {

            ArrayList<NewClassKehuModel> list = new ArrayList<NewClassKehuModel>();
            for (int i = 0; i < getpaydepositdetail.getCustomerFamilyList().size(); i++) {
                NewClassKehuModel m = new NewClassKehuModel();
                m.setCode(getpaydepositdetail.getCustomerFamilyList().get(i).getDocumentNumber());
                m.setName(getpaydepositdetail.getCustomerFamilyList().get(i).getMemberName());
                m.setNumber("" + (i + 1));
                list.add(m);
            }
            // 家庭成员加载
            adapter = new NewFromAdapter(NewFromActivity.this, list);
            kehuxinxi.setAdapter(adapter);
            adapter.SetType(1);
        }

        payDepositCode_view.setText(getpaydepositdetail.getPayDepositCode());

        payDepositMoney_view.setText(getpaydepositdetail.getPayDepositMoney());

        p_jjr.setText(getpaydepositdetail.getAgentId());

        from_time.setText(getpaydepositdetail.getPayDepositDate());

        remark_view.setText(getpaydepositdetail.getRemark());

        if (null != getpaydepositdetail.getImageList() && getpaydepositdetail.getImageList().size() > 0) {
            for (int i = 0; i < getpaydepositdetail.getImageList().size(); i++) {
                AddpirModel a = new AddpirModel();
                a.setIsnet("2");
                a.setType("1");
                a.setPath("" + getpaydepositdetail.getImageList().get(i).getSmallUrl());
                ap.add(0, a);
                ImageItem ima = new ImageItem();
                ima.type = "2";
                ima.imageId = EmmApplication.geTimes() + i;
                ima.sourcePath = getpaydepositdetail.getImageList().get(i).getSmallUrl();
                EmmApplication.pir.add(ima);
                ap2.add(a);
            }
        }

        padapter.SetDate(ap);

        if ("0".equals(getpaydepositdetail.getAnnexNum()) || null == getpaydepositdetail.getAnnexNum()
                || "null".equals(getpaydepositdetail.getAnnexNum())) {
            annex_layout.setVisibility(View.GONE);
        } else {
            annexNum_view.setText("存在以下" + getpaydepositdetail.getAnnexNum() + "个非图片附件，请通过电脑端查看  ");
            annex_layout.setVisibility(View.VISIBLE);
            AnnexAdapter annexAdapter = new AnnexAdapter(NewFromActivity.this, getpaydepositdetail.getAnnexList());
            annexList_list.setAdapter(annexAdapter);
        }

    }

    /**
     * 新增认筹
     */
    AddPayDeposit addpaydeposit;

    /**
     * <p>
     * <b>Title：</b> 新增认筹
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param auditStatus 0、待提交；1、待审核
     * @param type        0 新增 type=1修改
     * @author tangxin
     * @date 2016年12月7日 下午3:44:42
     */
    private void addPayDeposit(ArrayList<ImageListInfo> contentList_, String auditStatus, int type) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        if (type == 0) {
            EmmApplication.updateUrl("addPayDeposit");
            map.put("customerId", customerId);
        } else {
            EmmApplication.updateUrl("editPayDeposit");
            map.put("payDepositId", payDepositId);
        }

        if (EmmApplication.isNull(wufangrc.getText().toString().trim())) {

            if ("是".equals(wufangrc.getText().toString().trim())) {
                map.put("isPayDeposit", "1");
            } else {
                map.put("isPayDeposit", "0");
                map.put("calculateArea", EmmApplication.room.getCalculateArea());
                map.put("discountPrice", EmmApplication.room.getDiscountPrice());
                map.put("discountTotalPrice", EmmApplication.room.getDiscountTotalPrice());
                if (EmmApplication.isNull(housing_btn.getText().toString().trim())) {
                    map.put("payDepositHouses", housing_btn.getText().toString().trim());
                } else {
                    handler.sendEmptyMessage(101);
                    return;
                }
                if (EmmApplication.isNull(FrdID)) {
                    map.put("roomId", FrdID);
                } else {
                    handler.sendEmptyMessage(101);
                    return;
                }
            }
        } else {
            handler.sendEmptyMessage(102);
            return;
        }
        map.put("payDepositCode", payDepositCode_view.getText().toString().trim());

        if (EmmApplication.isNull(payDepositMoney_view.getText().toString().trim())) {
            map.put("payDepositMoney", payDepositMoney_view.getText().toString().trim());
        } else {
            handler.sendEmptyMessage(103);
            return;
        }
        if (EmmApplication.isNull(from_time.getText().toString().trim())) {
            map.put("payDepositDate", EmmApplication.replaceTime(from_time.getText().toString().trim()));
        } else {
            handler.sendEmptyMessage(104);
            return;
        }

        // 备注
        if (EmmApplication.isNull(remark_view.getText().toString().trim())) {
            map.put("remark", remark_view.getText().toString().trim());
        }

        map.put("auditStatus", auditStatus);

        if (null != getconsultan && null != getconsultan.getConsultantList()) {
            if (EmmApplication.isNull(p_jjr.getText().toString())) {
                int i = 0;
                for (int u = 0; u < getconsultan.getConsultantList().size(); u++) {
                    if (p_jjr.getText().toString()
                            .equals(getconsultan.getConsultantList().get(u).getConsultantUserName())) {
                        map.put("agentId", getconsultan.getConsultantList().get(u).getConsultantUserId());
                        i++;
                    }
                }
                if (i <= 0) {
                    handler.sendEmptyMessage(105);
                    return;
                }
            } else {
                handler.sendEmptyMessage(105);
                return;
            }
        } else {
            map.put("agentId", EmmApplication.getUserId());
        }

        if (EmmApplication.isNull(memberName_view.getText().toString().trim())) {
            map.put("memberName", memberName_view.getText().toString().trim());
        } else {
            handler.sendEmptyMessage(106);
            return;
        }

        // 证件类型：1、身份证；2、护照；3、营业执照；4、户口薄；5、军官证；
        // 6、临时身份证；7、港澳台同胞来往通行证；8、边民出入境通行证；
        // 9、外国人永久居留证；10、警官证；11、士兵证；12、其他
        Log.v(TAG, "身份证" + zj_type.getText().toString().trim());
        if (EmmApplication.isNull(zj_type.getText().toString().trim())) {

            if (null != DocumentType && DocumentType.size() > 0) {
                for (int i = 0; i < DocumentType.size(); i++) {
                    if (zj_type.getText().toString().trim().equals(DocumentType.get(i).getDictionaryName())) {
                        map.put("documentType", DocumentType.get(i).getDictionaryId());
                    }
                }
            } else {
                handler.sendEmptyMessage(107);
                return;
            }
        } else {
            // EmmApplication.T("请选择证件类型");
            // return;
        }

        // 证件号码
        if (EmmApplication.isNull(documentNumber_vew.getText().toString().trim())) {
            if ("身份证".equals(zj_type.getText().toString().trim())) {
                if (EmmApplication.isTrueCode(documentNumber_vew.getText().toString().trim())) {
                    map.put("documentNumber", documentNumber_vew.getText().toString().trim());
                } else {
                    handler.sendEmptyMessage(108);
                    return;
                }
            } else {
                map.put("documentNumber", documentNumber_vew.getText().toString().trim());
            }
        } else {
            // EmmApplication.T("请填写证件号码");
            // return;
        }

        // 手机号码
        if (EmmApplication.isNull(peMobile_view.getText().toString().trim())) {
            map.put("mobile", peMobile_view.getText().toString().trim());
        } else {
            handler.sendEmptyMessage(109);
            return;
        }

        // 邮寄地址
        if (EmmApplication.isNull(select_address.getText().toString().trim())) {
            map.put("mailPost", select_address.getText().toString().trim());
        } else {
            handler.sendEmptyMessage(110);
            return;
        }

        // 邮编
        if (EmmApplication.isNull(pePostcode_view.getText().toString().trim())) {
            map.put("postcode", pePostcode_view.getText().toString().trim());
        } else {
            // EmmApplication.T("请填写邮编");
            // return;
        }

        map.put("type", "2");

        map.put("category", "1");

        // 图片附件
        map.put("imageList", contentList_);

        ArrayList<CustomerFamilyListInfo> customerFamilyList = new ArrayList<NewFromActivity.CustomerFamilyListInfo>();

        for (int i = 0; i < list.size(); i++) {
            CustomerFamilyListInfo f = new CustomerFamilyListInfo();
            if (!EmmApplication.isNull(list.get(i).getName())) {
                handler.sendEmptyMessage(111);
                // break;
                return;
            }
            if (!EmmApplication.isNull(list.get(i).getType())) {
                handler.sendEmptyMessage(112);
                // break;
                return;
            }
            if (!EmmApplication.isNull(list.get(i).getCode())) {
                handler.sendEmptyMessage(113);
                // break;
                return;
            }
            f.setDocumentNumber(list.get(i).getCode());
            String stn = list.get(i).getType();
            if (null != DocumentType && DocumentType.size() > 0) {
                for (int y = 0; y < DocumentType.size(); y++) {
                    if (stn.equals(DocumentType.get(y).getDictionaryName())) {
                        f.setDocumentType(DocumentType.get(y).getDictionaryId());
                    }
                }
            } else {
                handler.sendEmptyMessage(114);
                return;
            }
            customerFamilyList.add(f);
        }
        map.put("customerFamilyList", customerFamilyList);

        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        if (type == 0) {
            Log.v("addPayDeposit-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        } else {
            Log.v("editPayDeposit-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        }
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                handler.sendEmptyMessage(115);
                handler.sendEmptyMessage(116);
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                handler.sendEmptyMessage(115);
                Log.v(TAG, "请求结束");
                handler.sendEmptyMessage(116);
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
                handler.sendEmptyMessage(117);
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }

                handler.sendEmptyMessage(116);

                Log.v("content", "content=>" + content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                addpaydeposit = JSONObject.parseObject(resData.toString(), AddPayDeposit.class);

                if ("1".equals(addpaydeposit.getResult())) {
                    Log.v("获取成功", "");
                    Loading.hideDialogForLoading();
                    finish();
                    // 发送广播，告知刷新界面
                    if (OpenType == 0) {
                        handler.sendEmptyMessage(118);
                        sendBroadcast(new Intent(EmmApplication.NEW_ON_CREATE_FROM_LIST));
                        EmmApplication.IS_RELOAD_DETAILS = true;
                    } else {
                        handler.sendEmptyMessage(119);
                        sendBroadcast(new Intent(EmmApplication.NEW_ON_CREATE_FROM));
                        EmmApplication.IsReload = 2;
                    }
                } else {
                    handler.sendEmptyMessage(120);
                    Log.v("获取失败", "errorCode:" + addpaydeposit.getErrorCode().toString() + "errorMsg:"
                            + addpaydeposit.getErrorMsg().toString());
                }
            }
        });
    }

    /**
     * 查询置业顾问列表数据源
     */
    GetConsultantList getconsultan;

    /**
     * 选择经纪人下标,默认-1为自己
     */
    private int agentId = -1;

    /**
     * <p>
     * <b>Title：</b> 查询置业顾问列表
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:45:32
     */
    private void getConsultantList() {
        EmmApplication.updateUrl("getConsultantList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("projectId", EmmApplication.getProjectID());
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getConsultantList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.hideDialogForLoading();
                Loading.showDialogForLoading(NewFromActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("置业顾问content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                getconsultan = JSONObject.parseObject(resData.toString(), GetConsultantList.class);
                if ("1".equals(getconsultan.getResult())) {
                    Log.v("获取成功", "");
                    if (getconsultan != null && getconsultan.getConsultantList() != null) {
                        if (getconsultan.getConsultantList().size() > 0) {
                            listname = new ArrayList<String>();
                            for (int i = 0; i < getconsultan.getConsultantList().size(); i++) {
                                listname.add(getconsultan.getConsultantList().get(i).getConsultantUserName());
                            }
                            SetzpPopu(listname, "经纪人", p_jjr, 1);
                        } else {
                            EmmApplication.T("当前没有经济人");
                        }
                    } else {
                        EmmApplication.T("当前没有经纪人");
                    }
                } else {
                    EmmApplication.T(getconsultan.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + getconsultan.getErrorCode().toString() + "errorMsg:"
                                + getconsultan.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("查询置业顾问", "错误信息获取空指针异常");
                    }
                }
            }
        });
    }

    /**
     * 客户详情
     */
    GetCustomerDetail details;

    /**
     * <p>
     * <b>Title：</b> 客户详情
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param customerId
     * @author tangxin
     * @date 2016年12月7日 下午3:46:11
     */
    private void getCustomerDetail(String customerId) {
        EmmApplication.updateUrl("getCustomerDetail");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("customerId", customerId);
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getCustomerDetail-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.hideDialogForLoading();
                Loading.showDialogForLoading(NewFromActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                details = JSONObject.parseObject(resData.toString(), GetCustomerDetail.class);
                if ("1".equals(details.getResult())) {
                    Log.v("获取成功", "");

                    memberName_view.setText(details.getCustomerName());
                    zj_type.setText(details.getPeDocumentType());
                    documentNumber_vew.setText(details.getPeDocumentNumber());
                    peMobile_view.setText(details.getCustomerPhone());
                    // String str1 = "";
                    // if ("".equals(details.getPeDomicilePlace()) ||
                    // "null".equals(details.getPeDomicilePlace())
                    // || TextUtils.isEmpty(details.getPeDomicilePlace())) {
                    // str1 = "";
                    // } else {
                    // str1 = details.getPeDomicilePlace() + "-";
                    // }
                    String str2 = "";
                    if ("".equals(details.getPeContactAddress()) || "null".equals(details.getPeContactAddress())
                            || TextUtils.isEmpty(details.getPeContactAddress())) {
                        str2 = "";
                    } else {
                        str2 = details.getPeContactAddress();
                    }
                    // str1 + "" +
                    select_address.setText(str2);
                    pePostcode_view.setText(details.getPePostcode());
                } else {
                    EmmApplication.T(details.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + details.getErrorCode().toString() + "errorMsg:"
                                + details.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("新增认筹+客户详情，错误信息获取空指针异常", "");
                    }

                }
            }
        });
    }

    // 【客户家庭成员信息】
    public class CustomerFamilyListInfo {
        private String memberName;// 客户姓名
        private String documentType;// 证件类型
        private String documentNumber;// 证件号码

        public String getMemberName() {
            return memberName;
        }

        public void setMemberName(String memberName) {
            this.memberName = memberName;
        }

        public String getDocumentType() {
            return documentType;
        }

        public void setDocumentType(String documentType) {
            this.documentType = documentType;
        }

        public String getDocumentNumber() {
            return documentNumber;
        }

        public void setDocumentNumber(String documentNumber) {
            this.documentNumber = documentNumber;
        }
    }

    /**
     * 证件类型
     */
    ArrayList<RqBusNumList> DocumentType;

    /**
     * 字典数据源
     */
    NewGetDictionaryList getdiction;

    /**
     * <p>
     * <b>Title：</b> 查询字典列表接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午4:08:25
     */
    private void getDictionaryList() {
        EmmApplication.updateUrl("getDictionaryListByProjectId");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("busNumType", "12");
        map.put("busNum", "01");
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getDictionaryList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v(TAG, "content==:" + content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }
                getdiction = JSONObject.parseObject(resData.toString(), NewGetDictionaryList.class);
                if ("1".equals(getdiction.getResult())) {
                    DocumentType = getdiction.getTypeMap().getDocumentType();
                } else {
                    EmmApplication.T(getdiction.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + getdiction.getErrorCode().toString() + "errorMsg:"
                            + getdiction.getErrorMsg().toString());
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        EmmApplication.IsLoadingFromList = false;// 解除限制
        unregisterReceiver(mBroadcastReceiver);
        EmmApplication.pir.clear();
        super.onDestroy();
    }

    /**
     * 菜单
     */
    public View view3;

    /**
     * 菜单
     */
    public PopupWindow popu_phone;

    /**
     * 拍照图片路径
     */
    private Uri mImageCaptureUri;

    private static final int PICK_FROM_CAMERA = 1;

    /**
     * <p>
     * <b>Title：</b> 点击添加图片按钮后的弹出框
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:32:06
     */
    public void popu() {
        view3 = LayoutInflater.from(NewFromActivity.this).inflate(R.layout.item_popupwindow, null);
        popu_phone = new PopupWindow(view3, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);

        popu_phone.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popu_phone.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        popu_phone.showAtLocation(view3, Gravity.BOTTOM, 0, 0);
        popu_phone.showAsDropDown(view3, 0, 0);
        popu_phone.setFocusable(true);
        popu_phone.setOutsideTouchable(true);
        view3.setFocusable(true);
        view3.setFocusableInTouchMode(true);

        view3.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    popu_phone.dismiss();
                }
                return false;
            }
        });

        view3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
            }
        });

        // 拍照
        Button item_popupwindows_camera = (Button) view3.findViewById(R.id.item_popupwindows_camera);
        // 相册
        Button item_popupwindows_Photo = (Button) view3.findViewById(R.id.item_popupwindows_Photo);
        // 取消
        Button item_popupwindows_cancel = (Button) view3.findViewById(R.id.item_popupwindows_cancel);

        item_popupwindows_cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
                EmmApplication.setLog(NewFromActivity.this);
            }
        });
        item_popupwindows_camera.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
                Album.camera(activity).start(PICK_FROM_CAMERA);
            }
        });
        item_popupwindows_Photo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EmmApplication.bitmap = null;
                popu_phone.dismiss();
                EmmApplication.setData("Picture", "1");
                EmmApplication.IsMoreSelect = true;
                startActivity(new Intent(NewFromActivity.this, ImageBucketChooseActivity.class));
            }
        });
    }

    /**
     * 回调方法
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.w("a", +requestCode + "resultCode===" + resultCode + "RESULT_OK======" + RESULT_OK);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case PICK_FROM_CAMERA:
                ImageItem item = new ImageItem();
                item.sourcePath = Album.parseResult(data).get(0);
                item.imageId = "1101841324";
                EmmApplication.pir.add(item);
                SetImage();
                break;
            case 0:
                System.out.println("相册");
                break;
            default:
                break;
        }
    }

    /**
     * 异步处理请求事件
     */
    class RecordTaskUpdate extends AsyncTask<Void, Integer, Void> {

        String auditStatus;// 0代表保存，1，代表提交审核

        int type = 0;

        public RecordTaskUpdate(String auditStatus, int type) {
            this.auditStatus = auditStatus;
            this.type = type;
        }

        @Override
        protected Void doInBackground(Void... arg0) {
            ArrayList<ImageListInfo> contentList_ = new ArrayList<ImageListInfo>();
            if (EmmApplication.pir.size() > 0) {
                for (int i = 0; i < EmmApplication.pir.size(); i++) {
                    if ("1".equals(EmmApplication.pir.get(i).type)) {
                        ImageListInfo content = new ImageListInfo();
                        content.setSignedUrl(EmmApplication.setPatchRtString(EmmApplication.pir.get(i).sourcePath));
                        content.setHeadType(".jpg");
                        contentList_.add(content);
                    }
                }
            } else {
                for (int m = 0; m < ap2.size(); m++) {
                    ImageListInfo content = new ImageListInfo();
                    content.setSignedUrl(ap2.get(m).getPath());
                    content.setHeadType("1");
                    contentList_.add(content);
                }
            }

            for (int m = 0; m < ap2.size(); m++) {
                int p = 0;
                for (int u = 0; u < EmmApplication.pir.size(); u++) {
                    if ("2".equals(EmmApplication.pir.get(u).type)) {
                        if (ap2.get(m).getPath().equals(EmmApplication.pir.get(u).sourcePath)) {
                            p++;
                        }
                    }
                }
                if (p > 0) {
                    ImageListInfo content = new ImageListInfo();
                    content.setSignedUrl(ap2.get(m).getPath());
                    content.setHeadType("0");
                    contentList_.add(content);
                } else {
                    ImageListInfo content = new ImageListInfo();
                    content.setSignedUrl(ap2.get(m).getPath());
                    content.setHeadType("1");
                    contentList_.add(content);
                }
            }

            addPayDeposit(contentList_, auditStatus, type);
            return null;
        }

        // 当在上面方法中调用publishProgress时，该方法触发,该方法在I线程中被执行
        protected void onProgressUpdate(Integer... progress) {
        }

        protected void onPostExecute(Void result) {
        }

        protected void onPreExecute() {
        }

    }

    Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what != 117) {
                hideDialog();
            }
            if (msg.what == 101) {
                EmmApplication.T("请选择意向房源");
            } else if (msg.what == 102) {
                EmmApplication.T("请选择是否无房认筹");
            } else if (msg.what == 103) {
                EmmApplication.T("请输入认筹金");
            } else if (msg.what == 104) {
                EmmApplication.T("请选择认筹日期");
            } else if (msg.what == 105) {
                EmmApplication.T2("请选择经纪人");
            } else if (msg.what == 106) {
                EmmApplication.T("请输入姓名");
            } else if (msg.what == 107) {
                PopuContent.poPu(NewFromActivity.this, "证件类型数据获取失败", false, 0);
            } else if (msg.what == 108) {
                EmmApplication.T("请填写正确的身份证号码");
            } else if (msg.what == 109) {
                EmmApplication.T("请输入手机号码");
            } else if (msg.what == 110) {
                EmmApplication.T("请选择邮寄地址");
            } else if (msg.what == 111) {
                EmmApplication.T("存在成员名称未填");
            } else if (msg.what == 112) {
                EmmApplication.T("存在成员证件类型未选");
            } else if (msg.what == 113) {
                EmmApplication.T("存在成员证件号未填");
            } else if (msg.what == 114) {
                PopuContent.poPu(NewFromActivity.this, "证件类型数据获取失败", false, 0);
            } else if (msg.what == 115) {
                // Loading.hideDialogForLoading();
            } else if (msg.what == 116) {
                is_sure.setEnabled(true);
                reject_btn.setEnabled(true);
            } else if (msg.what == 117) {
                is_sure.setEnabled(false);
                reject_btn.setEnabled(false);
            } else if (msg.what == 118) {
                EmmApplication.T("新增成功");
            } else if (msg.what == 119) {
                EmmApplication.T("修改成功");
            } else if (msg.what == 120) {
                EmmApplication.T(addpaydeposit.getErrorMsg().toString());
            }
        }

        ;
    };

    private void hideDialog() {
        Loading.hideDialogForLoading();
    }

}
